// 合理性检测
const { getOneConInfo } = require("../service/content.service");
const { conAlreadyExisted ,conaddError} = require("../constant/err.type")
const contentVerify = async (ctx, next) => {
    const { id,name } = ctx.request.body;
    try {
        const res = await getOneConInfo({ id,name });

        if (res) {
            console.error("内容已经存在", ctx.request.body);
            ctx.app.emit("error", conAlreadyExisted, ctx);
            return;
        }
    } catch (err) {
        console.error("获取用户名失败", err);
        ctx.app.emit("error", conaddError, ctx);
        return;
    }

    await next();
}
module.exports = {  contentVerify };